package com.example.iconmaker;

import java.util.ArrayList;
import java.util.List;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

class GLImage
{
	public static final int BG_COUNT = 17;
	public static final int MASK_COUNT = 3;
	public static final int ICON_COUNT = 3;
	
	public static final String BG_PRENAME = "bg";
	public static final String MASK_PRENAME = "mask";
	public static final String ICON_PRENAME = "icon";
	
	public static final int IMAGE_SIZE = 128; 
	
	public static List<Bitmap> bgs;
	public static List<Bitmap> masks;
	public static List<Bitmap> icons;
	public static void load(Resources resources){
		try {
			if(bgs == null){
				bgs = load(BG_PRENAME, BG_COUNT, resources);
			}
			if(masks == null){
				masks = load(MASK_PRENAME, MASK_COUNT, resources);
			}
			if(icons == null){
				icons = load(ICON_PRENAME, ICON_COUNT, resources);
			}
			
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static List<Bitmap> load(String preName, int count, Resources resources) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException{
		Class drawable = R.drawable.class;
		Bitmap b = null;
		List<Bitmap> list = new ArrayList<Bitmap>();
		for(int i=1;i<=count;i++){
			int r = drawable.getField(preName + i).getInt(null);
            b = BitmapFactory.decodeResource(resources, r);
			Bitmap b2 = Bitmap.createScaledBitmap(b, IMAGE_SIZE, IMAGE_SIZE, true);
			b.recycle();
			list.add(b2);
		}
		return list;
	}
}
